<template>
  <a-modal
    :title="title"
    :width="width"
    :visible="visible"
    @cancel="handleCancel"
    :footer="null"
    cancelText="关闭">

    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{y:500}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap">
        <span slot="action" slot-scope="text, record">
            <a @click="placeOrderDetail(record)">详情</a>
        </span>
      </a-table>
    </div>
    <place-order-material-detail-modal ref="placeOrderMaterialDetailModal"></place-order-material-detail-modal>
  </a-modal>
</template>

<script>
  import { filterObj } from '@/utils/util'
  import { getAction, postAction,putAction } from '@/api/manage'
  import placeOrderMaterialDetailModal from './placeOrderMaterialDetailModal'

  export default {
    name: "placeOrderRecord",
    components:{
      placeOrderMaterialDetailModal,
    },
    data() {
      return {
        width: '90%',
        model: {},
        title: "",
        columns:[
          {
            title: '#',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: "center",
            customRender: function (t, r, index) {
              return parseInt(index) + 1;
            },
            fixed: 'left'
          },
          {
            title:'下单编号',
            align:"center",
            dataIndex: 'placeOrderNo'
          },
          {
            title:'客户姓名',
            align:"center",
            dataIndex: 'customerInfo.name'
          },
          {
            title:'项目地址',
            align:"center",
            dataIndex: 'customerInfo.address'
          },
          {
            title:'下单时间',
            align:"center",
            dataIndex: 'placeOrderTime'
          },
          {
            title:'送达时间',
            align:"center",
            dataIndex: 'deliveredTime'
          },
          {
            title:'确认送达时间',
            align:"center",
            dataIndex: 'confirmDeliveredTime',
            customRender:function (text) {
              if (text != null){
                return text
              }else {
                return "-"
              }
            }
          },
          {
            title:'送达状态',
            align:"center",
            dataIndex: 'deliveredStatus',
            customRender:function (text) {
              if (text == 1){
                return "准时送达"
              }else if (text == 2){
                return "超时送达"
              }else {
                return "-"
              }
            }
          },
          {
            title:'创建人',
            align:"center",
            dataIndex: 'createBy'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: "center",
            fixed: "right",
            width: 90,
            scopedSlots: {
              customRender: 'action'
            },
          }
        ],
        visible: false,
        // 查询条件
        queryParam: {},
        //数据集
        dataSource: [],
        loading: false,
        selectedRowKeys: [],
        selectedRows: [],
        ipagination:{
          current: 1,
          pageSize: 10,
          pageSizeOptions: ['10', '20', '30'],
          showTotal: (total, range) => {
            return range[0] + "-" + range[1] + " 共" + total + "条"
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0
        },
        url: {
          placeOrderList: "/ghProjectPlaceOrder/placeOrderList",
          placeOrderEdit: "/ghProjectPlaceOrder/edit",
        },
        currentCustomerId: 0,
      }
    },
    created() {

    },
    methods: {
      handleCancel() {
        this.visible = false;
        this.onClearSelected();
      },
      loadData(arg) {
        this.loading = true;
        if (arg === 1) {
          this.ipagination.current = 1;
        }
        let params = {};
        params.customerId = this.currentCustomerId;
        getAction(this.url.placeOrderList,params).then((res) => {
          if (res.success) {
            this.dataSource = res.result.records || res.result;
            if (res.result.total) {
              this.ipagination.total = res.result.total;
            } else {
              this.ipagination.total = 0;
            }
          } else {
            this.$message.warning(res.message)
          }
        }).finally(() => {
          this.loading = false
        })
      },
      onClearSelected() {
        this.selectedRowKeys = [];
        this.selectedRows = [];
      },

      show(customerId){
        this.currentCustomerId = customerId;
        this.visible = true;
        this.title = "材料下单列表";
        this.loadData(1);
      },
      //下单详情
      placeOrderDetail(record){
        this.$refs.placeOrderMaterialDetailModal.show(record);
      },
    }
  }
</script>

<style scoped>
  .ant-card-body .table-operator {
    margin-bottom: 18px;
  }

  .ant-table-tbody .ant-table-row td {
    padding-top: 15px;
    padding-bottom: 15px;
  }

  .anty-row-operator button {
    margin: 0 5px
  }

  .ant-btn-danger {
    background-color: #ffffff
  }

  .ant-modal-cust-warp {
    height: 100%
  }

  .ant-modal-cust-warp .ant-modal-body {
    height: calc(100% - 110px) !important;
    overflow-y: auto
  }

  .ant-modal-cust-warp .ant-modal-content {
    height: 90% !important;
    overflow-y: hidden
  }
</style>